import PrimeNumber
class Fraction:
    """ Ratio Number """
    def __init__(self, numerator, denominator = 1):
        self.numerator = numerator
        self.denominator = denominator
        
    def __add__(self, other):
        cDenominator = PrimeNumber.getLCM(self.denominator, other.denominator)
        cNumerator = (cDenominator / self.denominator) * self.numerator  + (cDenominator / other.denominator) * other.numerator
        return Fraction(cNumerator, cDenominator)
    
    def __iadd__(self, other):
        cDenominator = PrimeNumber.getLCM(self.denominator, other.denominator)
        cNumerator = (cDenominator / self.denominator) * self.numerator  + (cDenominator / other.denominator) * other.numerator
        self.numerator = cNumerator
        self.denominator = cDenominator
        
        return self
        
    
    def __repr__(self):
        return str(self.numerator) + "/" + str(self.denominator)
    
    def reduce(self):
        """ reduction of a fraction (to its lowest terms) """
        gcm = PrimeNumber.getGCM(self.numerator, self.denominator)
        
        if gcm != 1:
            return Fraction(self.numerator / gcm, self.denominator / gcm)
        else:
            return self
